﻿using System;
using System.Data;
using System.Configuration;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Microsoft.ApplicationBlocks.Data;
using StillVoiceCommon;
using System.Data.SqlClient;

namespace TeamTime.Classes
{
    public class Enterprise : DataTableRow
    {

        public int OfficeID { get; set; }
        public Enterprise()
        {
            this.initClass(TN5Y.Utilities.DBConnectionString, "Enterprise");
        }
    
        public new void load(int id)
        {
            base.load(id);
            SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text,
                "select * from ViewEnterprises where ID = @ID",
                new SqlParameter("ID", id));
            if (dr.Read())
            {
                OfficeID = Convert.ToInt32(dr["OfficeID"]);
            }
            dr.Close();
            dr = null;
        }

        internal DataSet getActivities()
        {
            string sql = "select *  " +
          " from ViewEnterpriseActivities t  where EnterpriseID = @EnterpriseID";

            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", Convert.ToInt32(this.KeyValue)));
        }

        internal DataSet getPersons()
        {
            string sql = "select p.* , c.CompanyName,  es.PersonID  as PersonIDShareHolder,  " +
            " from ViewPersons p " +
            " inner join CompanyPerson cp on p.ID = cp.PersonID " +
            " inner join Company c on cp.CompanyID = c.ID " +
            " inner join Enterprise e on c.ID = e.CompanyID " +
            " left join EnterpriseShareholder es on es.EnterpriseID = @EnterpriseID and p.ID = es.PersonID " +
            " where e.ID = @EnterpriseID";

            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", Convert.ToInt32(this.KeyValue)));
        }

        internal DataSet getFundingApplications()
        {

            string sql = "SELECT * FROM ViewFundingApplications  where EnterpriseID = @EnterpriseID";

            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", Convert.ToInt32(this.KeyValue)));
        }

        internal DataSet getShareHolders()
        {
            string sql = "SELECT * FROM ViewEnterpriseShareHolders p where EnterpriseID = @EnterpriseID order by FullName";

            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", Convert.ToInt32(this.KeyValue)));
        }

        internal DataSet getProgressReports()
        {
            string sql = "SELECT * FROM ViewEnterpriseProgressReports p where EnterpriseID = @EnterpriseID order by ReportDate desc";

            return SqlHelper.ExecuteDataset(TN5Y.Utilities.DBConnectionString, CommandType.Text, sql,
                new SqlParameter("EnterpriseID", Convert.ToInt32(this.KeyValue)));
        }

      
    }


    public class EnterpriseActivity : DataTableRow
    {
        private string usernameModifiedBy;

        public new string UserNameModifiedBy
        {
            get { return usernameModifiedBy; }
            set { usernameModifiedBy = value; }
        }

        private string activity;
        public string Activity
        {
            get { return activity; }
            set { activity = value; }
        }

        public EnterpriseActivity()
        {
            this.initClass(TN5Y.Utilities.DBConnectionString, "EnterpriseActivity");
        }
        public new void load(string id)
        {
            base.load(id);
            SqlDataReader dr = SqlHelper.ExecuteReader(TN5Y.Utilities.DBConnectionString, CommandType.Text,
                "select * from ViewEnterpriseActivities where ID = @ID",
                new SqlParameter("ID", id));
            if (dr.Read())
            {
                usernameModifiedBy = dr["UserNameModifiedBy"].ToString();
                activity = dr["Activity"].ToString();
            }
            dr.Close();
            dr = null;
        }
    }
}
